#include <fstream>
#include <string>
#include "eeeinterface.h"

using namespace std;

eeeIface::eeeIface()
{
   tempFile = "/proc/eee/temperature";
   fsbFile = "/proc/eee/fsb";
   fanManualFile = "/proc/eee/fan_manual";
   fanRpmFile = "/proc/eee/fan_rpm";
   fanSpeedFile = "/proc/eee/fan_speed";
}

int eeeIface::getValSimp(string f)
{
   string line;
   ifstream file(f.data());
   if(file.is_open()) getline(file,line);
   else error();
   file.close();
   return atoi(line.data());
}

int eeeIface::getFsb()
{
   string line;
   ifstream file(fsbFile.data());
   if(file.is_open()) getline(file,line);
   else error();
   file.close();
   
   string getfsb;
   int i;
   for(i = 0; line[i] != ' '; i++) getfsb += line[i];
   
   return atoi(line.data());
}

int eeeIface::getTemp()
{
   return getValSimp(tempFile);
}

bool eeeIface::getFanManual()
{
   return getValSimp(fanManualFile);
}

int eeeIface::getFanRpm()
{
   return getValSimp(fanRpmFile);
}

int eeeIface::getFanSpeed()
{
   return getValSimp(fanSpeedFile);
}

void eeeIface::setFsb(int val)
{
   if(val >= 70 && val <=100)
     {
	ofstream file;
	file.open(fsbFile.data());
	file << val << " 24" << " 1";
	file.close();
     }
   else
     error();
}

void eeeIface::setFanSpeed(int val)
{
   if(val >= 0 && val <=100)
     {
	ofstream file;
	file.open(fanSpeedFile.data());
	file << val;
	file.close();
     }
   else
     error();
}

void eeeIface::setFanManual(bool val)
{
   ofstream file;
   file.open(fanManualFile.data());
   file << val;
   file.close();
}

void eeeIface::error() 
{
   //
}
